#!/usr/bin/env python3
PACKAGE = "dvxplorer_ros_driver"

from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

dvs_grp = gen.add_group("Dynamic Vision Sensor")

dvs_grp.add("dvs_enabled", bool_t, (0x01 << 0), "enables DVS", True)

bias_sensitivity_enum = gen.enum([
    gen.const("Very_Low",  int_t, 0, "Very low contrast sensitivity"),
    gen.const("Low",       int_t, 1, "Low contrast sensitivity"),
    gen.const("Default",   int_t, 2, "Default contrast sensitivity"),
    gen.const("High",      int_t, 3, "High contrast sensitivity"),
    gen.const("Very_High", int_t, 4, "Very high contrast sensitivity")
    ], "Bias sensitivity")
dvs_grp.add("bias_sensitivity", int_t, (0x01 << 0), "Bias sensitivity", 2, 0, 4, edit_method=bias_sensitivity_enum)

subsample_grp = dvs_grp.add_group("Subsampling")

subsample_enum = gen.enum([
    gen.const("None",   int_t, 0, "No subsampling"),
    gen.const("Half",   int_t, 1, "1/2 subsampling"),
    gen.const("Fourth", int_t, 3, "1/4 subsampling"),
    gen.const("Eighth", int_t, 7, "1/8 subsampling")
    ], "Subsample factor")

subsample_grp.add("subsample_enable", bool_t, (0x01 << 1), "Enable subsampling", False)
subsample_grp.add("subsample_vertical", int_t, (0x01 << 1), "Vertical subsampling", 0, 0, 7, edit_method=subsample_enum)
subsample_grp.add("subsample_horizontal", int_t, (0x01 << 1), "Horizontal subsampling", 0, 0, 7, edit_method=subsample_enum)

polarity_grp = dvs_grp.add_group("Polarity control")

polarity_grp.add("polarity_on_only", bool_t, (0x01 << 2), "only send ON polarity events", False)
polarity_grp.add("polarity_off_only", bool_t, (0x01 << 2), "only send OFF polarity events", False)
polarity_grp.add("polarity_flatten", bool_t, (0x01 << 2), "flatten all polarities to ON", False)

roi_grp = dvs_grp.add_group("DVS region of interest")

roi_grp.add("roi_enabled", bool_t, (0x01 << 3), "enable DVS region of interest", False)
roi_grp.add("roi_start_column", int_t, (0x01 << 3), "start position on the X axis for DVS region of interest", 0, 0, 639)
roi_grp.add("roi_start_row", int_t, (0x01 << 3), "start position on the Y axis for DVS region of interest", 0, 0, 479)
roi_grp.add("roi_end_column", int_t, (0x01 << 3), "end position on the X axis for DVS region of interest", 639, 0, 639)
roi_grp.add("roi_end_row", int_t, (0x01 << 3), "end position on the Y axis for DVS region of interest", 479, 0, 479)

imu_grp = gen.add_group("Inertial Measurement Unit")

imu_grp.add("imu_enabled", bool_t, (0x01 << 4), "enables IMU", True)

imu_acc_scale_enum = gen.enum([
    gen.const("2g",  int_t, 0, "+/- 2 g"),
    gen.const("4g",  int_t, 1, "+/- 4 g"),
    gen.const("8g",  int_t, 2, "+/- 8 g"),
    gen.const("16g", int_t, 3, "+/- 16 g")
    ], "Full scale of the accelerometer")

imu_gyro_scale_enum = gen.enum([
    gen.const("2000degps", int_t, 0, "+/- 2000 deg/s"),
    gen.const("1000degps", int_t, 1, "+/- 1000 deg/s"),
    gen.const("500degps",  int_t, 2, "+/- 500 deg/s"),
    gen.const("2500degps", int_t, 3, "+/- 250 deg/s"),
    gen.const("125degps",  int_t, 4, "+/- 125 deg/s")
    ], "Full scale of the gyroscope")

imu_grp.add("imu_acc_scale", int_t, (0x01 << 4), "Full scale of the accelerometer", 1, 0, 3, edit_method=imu_acc_scale_enum)
imu_grp.add("imu_gyro_scale", int_t, (0x01 << 4), "Full scale of the gyroscope", 2, 0, 4, edit_method=imu_gyro_scale_enum)

gen.add("streaming_rate", int_t, (0x01 << 5), "integration time (0 is instant sending)", 30, 0, 10000)
gen.add("max_events", int_t, (0x01 << 5), "maximum events per packet (0 is no limit)", 0, 0, 100000)

exit(gen.generate(PACKAGE, "dvxplorer_ros_driver", "DVXplorer_ROS_Driver"))
